// offspiral.txt. Charged spiral, but it's not connected to what it's supposed to 
// be powering. Use to connect it.
// Cell 0 - difficulty
// Cell 1,2 - Stuff done flag. Set to 1 when connected.

beginobjectscript;

variables;
	short desc_text = 0;
	
body;

beginstate INIT_STATE;
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; 
	if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0)) {
		if (get_flag(get_memory_cell(1),get_memory_cell(2)) > 0) {
			if (get_ran(1,0,100) < 40)
				create_text_bubble("Hummmm...");
			
			if (get_ran(1,0,100) < 40)
				run_sparkles_on_object(ME,8,5,1);							
			}
			else {
				if (get_ran(1,0,100) < 20)
					create_text_bubble("Fizzle.");
				}
		}	
break;


beginstate USE_STATE;
	if (desc_text == 0) {
		print_str_color("Power Spiral: It is active, but it has come unhooked from",2);
		print_str_color("  the crystal fibers it is supposed to be powering. Use the",2);
		print_str_color("  spiral again to attempt to hook it up.",2);
		desc_text = 1;
		end();
		}
		
	if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0)) {
		if (get_flag(get_memory_cell(1),get_memory_cell(2)) > 0) {
			print_str_color("Power Spiral: It's already been activated.",2);
			end();
			}
		}

	if (get_stat(21) < get_memory_cell(0)) {
		print_str_color("Power Spiral: Your skill is insufficient to activate it.",2);
		end();
		}
		else {
			play_sound(167);
			if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0))
				set_flag(get_memory_cell(1),get_memory_cell(2),1);
			print_str_color("Power Spiral: You turn on the power.",2);
			}
break;

beginstate ITEM_USED_STATE;
	if (item_used_on_me() != 255) {
		print_str_color("Use Tool: You need a Living Tool to affect the spiral.",2);
		end();
		}
	if (get_stat(21) == 0) {
		print_str_color("Use Tool: You need some Mechanics skill to use a tool.",2);
		end();
		}
	if (get_memory_cell(0) > 2 * get_stat(21)) {
		print_str_color("Use Tool: You use up the tool working on the spiral. It will be",2);
		print_str_color("  easier to activate now.",2);
		set_memory_cell(0,get_memory_cell(0) - 2 * get_stat(21));
		drain_charge_of_used_object();
		end();
		}
		else {
			print_str_color("Use Tool: The spiral connections are now repaired. Use the spiral",2);
			print_str_color("  to activate it.",2);
			}
	set_memory_cell(0,0);
break;